﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace cs_utilities.assembly
{
    public class assembly_info
    {
        private Assembly asm = null;

        //---------------------------------------------------------------------------
        public string AssemblyTitle
        {
            get
            {
                object[] attributes = asm.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(asm.CodeBase);
            }
        }
        //---------------------------------------------------------------------------
        public string AssemblyVersion
        {
            get
            {
                return asm.GetName().Version.ToString();
            }
        }
        //---------------------------------------------------------------------------
        public string AssemblyDescription
        {
            get
            {
                object[] attributes = asm.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }
        //---------------------------------------------------------------------------
        public string AssemblyProduct
        {
            get
            {
                object[] attributes = asm.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }
        //---------------------------------------------------------------------------
        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = asm.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }
        //---------------------------------------------------------------------------
        public string AssemblyCompany
        {
            get
            {
                object[] attributes = asm.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        //---------------------------------------------------------------------------
        public assembly_info()
        {
            this.asm = Assembly.GetCallingAssembly();
        }
        //---------------------------------------------------------------------------
        public assembly_info(Assembly asm)
        {
            this.asm = asm;
        }
        //---------------------------------------------------------------------------
    }
}